home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html;
-
- import java.awt.Component;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.Reader;
- import java.io.StringReader;
- import java.io.Writer;
- import java.lang.reflect.Method;
- import java.net.URL;
- import javax.swing.Action;
- import javax.swing.JEditorPane;
- import javax.swing.text.AbstractDocument;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.Document;
- import javax.swing.text.Element;
- import javax.swing.text.MutableAttributeSet;
- import javax.swing.text.Style;
- import javax.swing.text.StyleConstants;
- import javax.swing.text.StyledDocument;
- import javax.swing.text.StyledEditorKit;
- import javax.swing.text.TextAction;
- import javax.swing.text.ViewFactory;
- import javax.swing.text.html.HTML.Attribute;
- import javax.swing.text.html.HTML.Tag;
-
- public class HTMLEditorKit extends StyledEditorKit {
- public static final String DEFAULT_CSS = "default.css";
- MutableAttributeSet input;
- private static StyleSheet defaultStyles = null;
- private MouseListener linkHandler = new LinkController();
- private static Parser defaultParser = null;
- private MouseMotionListener tmpHandler = new TemporaryHandler();
- public static final String BOLD_ACTION = "html-bold-action";
- public static final String ITALIC_ACTION = "html-italic-action";
- public static final String PARA_INDENT_LEFT = "html-para-indent-left";
- public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
- public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
- public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
- public static final String COLOR_ACTION = "html-color-action";
- public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
- public static final String IMG_ALIGN_TOP = "html-image-align-top";
- public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
- public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
- public static final String IMG_BORDER = "html-image-border";
- private static final String INSERT_TABLE_HTML = "<table border=1><tr><td></td></tr></table>";
- private static final String INSERT_UL_HTML = "<ul><li></li></ul>";
- private static final String INSERT_OL_HTML = "<ol><li></li></ol>";
- private static final String INSERT_HR_HTML = "<hr>";
- private static final String INSERT_PRE_HTML = "<pre></pre>";
- private static final Action[] defaultActions;
- // $FF: synthetic field
- static Class class$javax$swing$text$html$HTMLEditorKit;
- // $FF: synthetic field
- static Class class$java$lang$String;
-
- static {
- defaultActions = new Action[]{new InsertHTMLTextAction("InsertTable", "<table border=1><tr><td></td></tr></table>", Tag.BODY, Tag.TABLE), new InsertHTMLTextAction("InsertTableRow", "<table border=1><tr><td></td></tr></table>", Tag.TABLE, Tag.TR, Tag.BODY, Tag.TABLE), new InsertHTMLTextAction("InsertTableDataCell", "<table border=1><tr><td></td></tr></table>", Tag.TR, Tag.TD, Tag.BODY, Tag.TABLE), new InsertHTMLTextAction("InsertUnorderedList", "<ul><li></li></ul>", Tag.BODY, Tag.UL), new InsertHTMLTextAction("InsertUnorderedListItem", "<ul><li></li></ul>", Tag.UL, Tag.LI, Tag.BODY, Tag.UL), new InsertHTMLTextAction("InsertOrderedList", "<ol><li></li></ol>", Tag.BODY, Tag.OL), new InsertHTMLTextAction("InsertOrderedListItem", "<ol><li></li></ol>", Tag.OL, Tag.LI, Tag.BODY, Tag.OL), new InsertHRAction(), new InsertHTMLTextAction("InsertPre", "<pre></pre>", Tag.BODY, Tag.PRE)};
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
-
- public Object clone() {
- return new HTMLEditorKit();
- }
-
- public Document createDefaultDocument() {
- StyleSheet var1 = this.getStyleSheet();
- StyleSheet var2 = new StyleSheet();
- var2.addStyleSheet(var1);
- HTMLDocument var3 = new HTMLDocument(var2);
- ((AbstractDocument)var3).putProperty(HTMLDocument.PARSER_PROPERTY, this.getParser());
- ((AbstractDocument)var3).setAsynchronousLoadPriority(4);
- var3.setTokenThreshold(100);
- return var3;
- }
-
- protected void createInputAttributes(Element var1, MutableAttributeSet var2) {
- var2.removeAttributes(var2);
- var2.addAttributes(var1.getAttributes());
- var2.removeAttribute(StyleConstants.ComposedTextAttribute);
- Object var3 = var2.getAttribute(StyleConstants.NameAttribute);
- if (var3 instanceof HTML.Tag) {
- HTML.Tag var4 = (HTML.Tag)var3;
- if (var4 == Tag.IMG) {
- var2.removeAttribute(Attribute.SRC);
- var2.removeAttribute(Attribute.HEIGHT);
- var2.removeAttribute(Attribute.WIDTH);
- var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- } else if (var4 == Tag.HR) {
- var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- } else if (var4 == Tag.COMMENT) {
- var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- var2.removeAttribute(Attribute.COMMENT);
- } else if (var4 instanceof HTML.UnknownTag) {
- var2.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- var2.removeAttribute(Attribute.ENDTAG);
- }
- }
-
- }
-
- public void deinstall(JEditorPane var1) {
- ((Component)var1).removeMouseListener(this.linkHandler);
- ((Component)var1).removeMouseMotionListener(this.tmpHandler);
- super.deinstall(var1);
- }
-
- public Action[] getActions() {
- return TextAction.augmentList(super.getActions(), defaultActions);
- }
-
- public String getContentType() {
- return "text/html";
- }
-
- public MutableAttributeSet getInputAttributes() {
- if (this.input == null) {
- this.input = this.getStyleSheet().addStyle((String)null, (Style)null);
- }
-
- return this.input;
- }
-
- protected Parser getParser() {
- if (defaultParser == null) {
- try {
- Class var1 = Class.forName("javax.swing.text.html.parser.ParserDelegator");
- defaultParser = (Parser)var1.newInstance();
- } catch (Throwable var2) {
- }
- }
-
- return defaultParser;
- }
-
- static InputStream getResourceAsStream(String var0) {
- try {
- ClassLoader var2 = (class$javax$swing$text$html$HTMLEditorKit != null ? class$javax$swing$text$html$HTMLEditorKit : (class$javax$swing$text$html$HTMLEditorKit = class$("javax.swing.text.html.HTMLEditorKit"))).getClassLoader();
- Class var1;
- if (var2 != null) {
- var1 = var2.loadClass("javax.swing.text.html.ResourceLoader");
- } else {
- var1 = Class.forName("javax.swing.text.html.ResourceLoader");
- }
-
- Class[] var3 = new Class[]{class$java$lang$String != null ? class$java$lang$String : (class$java$lang$String = class$("java.lang.String"))};
- Method var4 = var1.getMethod("getResourceAsStream", var3);
- String[] var5 = new String[]{var0};
- return (InputStream)var4.invoke((Object)null, var5);
- } catch (Throwable var6) {
- return (class$javax$swing$text$html$HTMLEditorKit != null ? class$javax$swing$text$html$HTMLEditorKit : (class$javax$swing$text$html$HTMLEditorKit = class$("javax.swing.text.html.HTMLEditorKit"))).getResourceAsStream(var0);
- }
- }
-
- public StyleSheet getStyleSheet() {
- if (defaultStyles == null) {
- defaultStyles = new StyleSheet();
-
- try {
- InputStream var1 = getResourceAsStream("default.css");
- BufferedReader var2 = new BufferedReader(new InputStreamReader(var1));
- defaultStyles.loadRules(var2, (URL)null);
- ((Reader)var2).close();
- } catch (Throwable var3) {
- }
- }
-
- return defaultStyles;
- }
-
- public ViewFactory getViewFactory() {
- return new HTMLFactory();
- }
-
- public void insertHTML(HTMLDocument var1, int var2, String var3, int var4, int var5, HTML.Tag var6) throws BadLocationException, IOException {
- Parser var7 = this.getParser();
- if (var7 == null) {
- throw new IOException("Can't load parser");
- } else if (var2 > ((AbstractDocument)var1).getLength()) {
- throw new BadLocationException("Invalid location", var2);
- } else {
- ParserCallback var8 = var1.getReader(var2, var4, var5, var6);
- Boolean var9 = (Boolean)((AbstractDocument)var1).getProperty("IgnoreCharsetDirective");
- var7.parse(new StringReader(var3), var8, var9 == null ? false : var9);
- var8.flush();
- }
- }
-
- public void install(JEditorPane var1) {
- ((Component)var1).addMouseListener(this.linkHandler);
- ((Component)var1).addMouseMotionListener(this.tmpHandler);
- super.install(var1);
- }
-
- public void read(Reader var1, Document var2, int var3) throws IOException, BadLocationException {
- if (var2 instanceof HTMLDocument) {
- HTMLDocument var4 = (HTMLDocument)var2;
- Parser var5 = this.getParser();
- if (var5 == null) {
- throw new IOException("Can't load parser");
- }
-
- if (var3 > var2.getLength()) {
- throw new BadLocationException("Invalid location", var3);
- }
-
- ParserCallback var6 = var4.getReader(var3);
- Boolean var7 = (Boolean)var2.getProperty("IgnoreCharsetDirective");
- var5.parse(var1, var6, var7 == null ? false : var7);
- var6.flush();
- } else {
- super.read(var1, var2, var3);
- }
-
- }
-
- public void setStyleSheet(StyleSheet var1) {
- defaultStyles = var1;
- }
-
- public void write(Writer var1, Document var2, int var3, int var4) throws IOException, BadLocationException {
- if (var2 instanceof HTMLDocument) {
- HTMLWriter var5 = new HTMLWriter(var1, (HTMLDocument)var2, var3, var4);
- var5.write();
- } else if (var2 instanceof StyledDocument) {
- MinimalHTMLWriter var6 = new MinimalHTMLWriter(var1, (StyledDocument)var2, var3, var4);
- var6.write();
- } else {
- super.write(var1, var2, var3, var4);
- }
-
- }
- }
-